package com.ly.hotel.view.fragments.game;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.ly.hotel.R;
import com.ly.hotel.common.MyApplication;
import com.ly.hotel.model.AppInfo;
import com.ly.hotel.util.ImageUtil;
import com.ly.hotel.util.LanguageUtil;

import java.util.List;

public class AppAdapter extends BaseAdapter {
	Context mContext;
	LayoutInflater mInflater;
	private List<AppInfo> appInfos;
	private int rod;

	public AppAdapter(Context c,List<AppInfo> appInfos) {
		this.appInfos = appInfos;
		mContext = c;
		mInflater = LayoutInflater.from(mContext);
		rod = mContext.getResources().getDimensionPixelSize(R.dimen.px12);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return appInfos.size();
	}

	@Override
	public Object getItem(int postion) {
		// TODO Auto-generated method stub
		return appInfos.get(postion);
	}

	@Override
	public long getItemId(int postion) {
		// TODO Auto-generated method stub
		return postion;
	}

	@Override
	public View getView(int postion, View contentView, ViewGroup arg2) {
		// TODO Auto-generated method stub
		ViewHolder holder;
		if (contentView == null) {
			holder = new ViewHolder();
			contentView = mInflater.inflate(R.layout.intro_gridview_item, null);
			holder.mImg = (ImageView) contentView.findViewById(R.id.m_App_Image);
			holder.mTxt= (TextView) contentView.findViewById(R.id.m_App_text);
			contentView.setTag(holder);
		} else {
			holder = (ViewHolder) contentView.getTag();
		}
		ImageUtil.displayImage_Round(mContext, MyApplication.getHostResUrl() + "upload/" + appInfos.get(postion).getIcon(), holder.mImg ,rod);
		holder.mTxt.setText(LanguageUtil.getTextFromLocalLanguage(appInfos.get(postion).getAppName()));
		return contentView;
	}
	static class ViewHolder {
		ImageView mImg;
		TextView mTxt;
	}
}
